from rest_framework.viewsets import ModelViewSet
from goods.models import SPUSpecification
from meiduo_admin.serializers.specs import SPUSpecificationSerializer
from meiduo_admin.utils import UserPageNum
from goods.models import SPU
from rest_framework.response import Response
from meiduo_admin.serializers.specs import SPUSerializer


class SpecsView(ModelViewSet):
    """商品规格的增删改查"""
    #  指定序列化器
    serializer_class = SPUSpecificationSerializer
    #  指定查询集
    queryset = SPUSpecification.objects.all()
    #  指定分页器
    pagination_class = UserPageNum

    def simple(self, request):
        spus = SPU.objects.all()
        ser = SPUSerializer(spus, many=True)
        return Response(ser.data)

    # def destroy(self, request, *args, **kwargs):
    #     spec = self.get_object()
    #     spec.is_delete = True  # 前提是数据库中有这个is_delete字段
    #     spec.save

